class Solution(object):
    def nextPermutation(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        for i in range(0, len(nums)-1)[::-1]:
            if nums[i] < nums[i+1]:
                for j in range(i+1, len(nums))[::-1]:
                    if nums[j] > nums[i]:
                        temp = nums[i]
                        nums[i] = nums[j]
                        nums[j] = temp
                        self.swap(i+1, len(nums)-1, nums)
                        return nums
        self.swap(0, len(nums)-1, nums)
        return nums

    def swap(self, left, right, nums):
        while left < right :
            temp = nums[left]
            nums[left] = nums[right]
            nums[right] = temp
            left += 1
            right -= 1


test = Solution()
print(test.nextPermutation([1,1,5]))